<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class notifyService extends MY_Service{
    
    public $aid;
    public function __construct($data) {
         parent::__construct();
        $this->aid = $data['aid'];
        $this->load->model('yyawards_record_model', 'record');
        $this->load->model('yyawards_cycle_model', 'cycle');
    }
    
    
    /**
     * 获取已读结果    
     */
    public function getResult($gid,$cycle){
        
        if(empty($gid)||empty($this->aid)||empty($cycle)){
            return false; //如果数据不存在,则不提醒
        }

        //获取上一期数据
        $this->load->model('yyawards_record_model', 'record');
        $info = $this->record->drawPartake(1,0,false,'gr.gid = '.$gid.' and gr.cycle = '.$cycle.' and gr.aid = '.$this->aid);  
        if(empty($info)||empty($info[0])){
            return false;  //如果上一期没有数据
        }
        if($info[0]['is_read'] == 1){
            return false;  //如果上一期已读
        }
        if($info[0]['is_read'] == 0){
            $r = $this->result->get_one('gid = '.$gid.' and cycle = '.$cycle);
            if(empty($r)){
                return false; //如果上一期未读,并且还未开奖
            }
        }
        //如果是未读状态，则返回上一期中奖数据，并更新已读状态 
        $this->record->updateRead($info[0]['gr_id']);           
        return $info[0]['r_aid'] == $this->aid ? '已中奖' : '未中奖';
    }
}